﻿using System;
using System.Collections.Generic;

using System.Text;
using Microsoft.SharePoint;
using System.Collections;

namespace isl.stsadm.ManageSPEventHandlerExtensions
{
    public class InstallerArgs
    {
        private System.Collections.Specialized.StringDictionary processedArgs;

        public InstallerArgs(System.Collections.Specialized.StringDictionary keyValues)
        {
            //convert passed in values to lowercase and store in this class
            processedArgs = new System.Collections.Specialized.StringDictionary();
            foreach (DictionaryEntry de in keyValues)
            {
                processedArgs.Add(de.Key.ToString().ToLower(),de.Value.ToString());
            }
        }

         

        public string SiteCollection
        {
            get
            {
                return processedArgs["sitecollection"];
            }
        }
        public string WebSite
        {
            get
            {
                return processedArgs["website"];
            }
        }
        public string ListName
        {
            get
            {
                return processedArgs["listname"];
            }
        }

        public string ReceiverAssembly
        {
            get
            {
                return processedArgs["receiverassembly"];
            }
        }
        public string Culture
        {
            get
            {
                return processedArgs["culture"];
            }
        }
        public string PublicKeyToken
        {
            get
            {
                return processedArgs["publickeytoken"];
            }
        }
        public string NameSpace
        {
            get
            {
                return processedArgs["namespace"];
            }
        }
        public string Version
        {
            get
            {
                return processedArgs["version"];
            }
        }

        public string ReceiverClass
        {
            get
            {
                return processedArgs["receiverclass"];
            }
        }


        public SPEventReceiverType AddEventType
        {
            get
            {
                if (processedArgs["addeventtype"] == null)
                {
                    throw new InvalidOperationException("Missing Event Type For addeventhandler command");
                }
                //SPEventReceiverType.ItemDeleting
                return (SPEventReceiverType)System.Enum.Parse(typeof(SPEventReceiverType), processedArgs["addeventtype"], true);
            }
        }

        public string Command
        {
            get
            {

                return NullIfEmpty("command");
            }
        }

        private string NullIfEmpty(string key)
        {
            if (processedArgs.ContainsKey(key))
            {
                return processedArgs[key];
            }
            else
            {
                return "";
            }
        }
    }
}
